package com.cristina.attention.utils;

import org.springframework.lang.Nullable;

/**
 * @author by Attention
 * @Classname NumberUtil
 * @Date 2021/12/8
 */
public class NumberUtil extends org.springframework.util.NumberUtils {

    public static long toLong(@Nullable final String str, final long defaultValue) {
        if (str == null) {
            return defaultValue;
        }
        try {
            return Long.valueOf(str);
        } catch (final NumberFormatException nfe) {
            return defaultValue;
        }
    }

    public static int toInt(@Nullable final String str, final int defaultValue) {
        if (str == null) {
            return defaultValue;
        }
        try {
            return Integer.valueOf(str);
        } catch (final NumberFormatException nfe) {
            return defaultValue;
        }
    }

}
